package siedler.communication;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Services extends UnicastRemoteObject implements ServicesI{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String hashAlgorithm;
	
	public Services(String algo)throws RemoteException{
		this.hashAlgorithm = algo;
	}
	
	public synchronized byte[] getHash(double rnd) throws RemoteException {
		
		MessageDigest hashFunction = null;
		try {
			hashFunction = MessageDigest.getInstance(hashAlgorithm);
		} catch (NoSuchAlgorithmException e) {
			System.out.println("Defined Hash-Algorithm is not available!");
			System.exit(1);
		} 
		byte[] input = Double.toString(rnd).getBytes(); 
		 
		hashFunction.update( input, 0, input.length ); 
		 
		return hashFunction.digest(); 
	}
	
}
